<template>
  <div class="wrap pd20">
    <div class="contant channel-global-set">
      <div class="tip">{{$t('configLazyLoad.webimClient.tips1')}}</div>
      <el-form label-position="top" ref="formSensitive" class="form">
        <el-form-item>
          <span class="title" style="margin-right: 30px">{{$t('configLazyLoad.webimClient.tips3')}}</span>
          <el-switch
            v-model="formMessages.focusSensitiveWords"
            :active-text="$t('configLazyLoad.public.open')"
            active-value="1"
            inactive-value="0"
            :inactive-text="$t('configLazyLoad.public.close')">
          </el-switch>
        </el-form-item>
        <p class="tip_item">{{$t('configLazyLoad.webimClient.tips2')}}</p>
        <el-form-item>
          <el-input type="textarea"  :maxlength="3000" :rows="4" v-model="formMessages.focusWords"></el-input>
        </el-form-item>
        <el-form-item>
          <span class="title" style="margin-right: 30px">{{$t('configLazyLoad.webimClient.markColor')}}</span>
          <el-color-picker v-model="formMessages.backgroundColor" class="color-picker" @change="changeColor"></el-color-picker>
          <span class="tip_item">{{$t('configLazyLoad.webimClient.chooseColor')}}</span>
        </el-form-item>
        <el-form-item v-if="isHasMenuShow('sensitive_message_sms')">
          <div class="smsNotify">
            <p class="smsCheck"><el-checkbox class="smsCheckLabel" v-model="formMessages.filterSensitiveMessage" true-label="1" false-label="0">{{$t('configLazyLoad.webimClient.smsNotify')}}</el-checkbox></p>
            <p class="timeTitle" v-show="formMessages.filterSensitiveMessage === '1'">{{$t('configLazyLoad.webimClient.timeChoose')}}（<span class="notifyDesc">{{$t('configLazyLoad.channel.globalTip6')}}</span>）：</p>
            <div class="timeZone" v-show="formMessages.filterSensitiveMessage === '1'">
              <p>{{$t('configLazyLoad.public.date')}}</p>
              <div class="notifyDate">
                <el-input v-model.trim="formMessages.filterMessageStartDate"></el-input>
                <el-input v-model.trim="formMessages.filterMessageEndDate"></el-input>
              </div>
              <p>{{$t('configLazyLoad.public.time')}}</p>
              <div class="notifyDate">
                <el-input v-model.trim="formMessages.filterMessageStartTime"></el-input>
                <el-input v-model.trim="formMessages.filterMessageEndTime"></el-input>
              </div>
              <p style="margin-bottom:5px;">{{$t('configLazyLoad.public.week')}}</p>
              <div>
                <el-checkbox v-model="formMessages.weekMon">{{$t('configLazyLoad.public.Mon')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekTue">{{$t('configLazyLoad.public.Tues')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekWed">{{$t('configLazyLoad.public.Wed')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekThu">{{$t('configLazyLoad.public.Thur')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekFri">{{$t('configLazyLoad.public.Fri')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekSat">{{$t('configLazyLoad.public.Sat')}}</el-checkbox>
                <el-checkbox v-model="formMessages.weekSun">{{$t('configLazyLoad.public.Sun')}}</el-checkbox>
              </div>
              <div class="prompit">
                {{$t('configLazyLoad.webimClient.tip')}}<br/>
                {{$t('configLazyLoad.webimClient.timeTip1')}}<br/>
                {{$t('configLazyLoad.webimClient.timeTip2')}}<br/>
              </div>
            </div>
            <div class="notifySmsTemp" v-show="formMessages.filterSensitiveMessage === '1'">
              <span class="notifyTitle"><i class="red">*</i>{{$t('configLazyLoad.webimClient.smsTemplate')}}</span>
              <el-select filterable v-model="formMessages.filterMessageTemp">
                <el-option :label="$t('public.pleasePick')" value="0"></el-option>
                <el-option
                  class="sms-select-option"
                  v-for="item in smsTemplates"
                  :key="item._id"
                  :label="item.displayname"
                  :value="item._id">
                  <b class="sms-title-b">{{ item.name }}:</b> <span>{{item.content}}</span>
                </el-option>
              </el-select>
              <p class="notifyDesc font12" style="padding-left: 90px">{{$t('configLazyLoad.webimClient.tips6')}}</p>
            </div>
            <div class="notifySmsNumber" v-show="formMessages.filterSensitiveMessage === '1'">
              <span class="notifyTitle">{{$t('configLazyLoad.webimClient.notifyPhone')}}</span>
                <el-input type="textarea" v-model="formMessages.filterSensitiveTel"
                          :autosize="{ minRows: 2}" :placeholder="$t('configLazyLoad.webimClient.tips7')">
                </el-input>
              <p style="padding-left: 90px;margin-top: 5px">{{$t('configLazyLoad.webimClient.tips8')}}<span class="red">{{filterSensitiveTelLength}}</span>{{$t('configLazyLoad.channel.globalTip7')}}</p>
            </div>
          </div>
        </el-form-item>
        <el-form-item>
          <span class="title" style="margin-right: 30px">{{$t('configLazyLoad.webimClient.content1')}}</span>
          <el-switch
            v-model="formMessages.filterSensitiveWords"
            :active-text="$t('configLazyLoad.public.open')"
            :inactive-text="$t('configLazyLoad.public.close')">
          </el-switch>
        </el-form-item>
        <p class="tip_item">{{$t('configLazyLoad.webimClient.tips9')}}</p>
        <el-form-item>
          <el-input type="textarea"  :maxlength="3000" :rows="4" v-model="formMessages.sensitiveWords"></el-input>
        </el-form-item>
        <div class="title">{{$t('configLazyLoad.webimClient.content2')}}</div>
        <el-form-item class="vip_access">
          <div class="label_box">{{$t('configLazyLoad.webimClient.content3')}}:</div>
          <el-switch v-model="formMessages.openPriority"></el-switch>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.tips10')}}</p>
        </el-form-item>
        <el-form-item class="priority_box" v-show="formMessages.openPriority">
          <div class="priority_title">{{$t('configLazyLoad.webimClient.intoLineConfig')}}：</div>
          <div class="priority_item" v-for="(item, index) in custArray" :key="index">
            <span class="priority_item_name">{{item.name}}</span>
            <el-checkbox class="" v-model="item.checked">{{$t('configLazyLoad.webimClient.intoLinePriority')}}</el-checkbox>
          </div>
          <div>
            <div class="title">优先进线参数自定义</div>
            当自定义字段customField.<el-input class="customFieldPriority" placeholder="进线参数" v-model.trim="formMessages.customFieldPriority"></el-input>等于
            <el-input type="textarea"  :maxlength="3000" :rows="4" v-model="formMessages.customFieldPriorityWords"></el-input>
            <span style="color:#595959">当存在多个值时，请用英文逗号或回车隔开</span>
          </div>
        </el-form-item>
        <div class="priority_title">{{$t('configLazyLoad.webimClient.tips4')}}  <a href="https://developer.7moor.com/online-service-kf02/" target="_blank">{{$t('configLazyLoad.webimClient.defaultTips22')}}</a></div>
        <el-form-item class="padding-top">
          <el-button type="primary" @click="saveFilterWords" class="fr primary_btn">{{$t('public.save')}}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips1')}}</div>
      <div class="title">{{$t('configLazyLoad.webimClient.leaveMessage')}}</div>
      <el-form label-position="top" ref="formMessages" :model="formMessages" class="form">
        <el-form-item :label="$t('configLazyLoad.webimClient.leaveMessageConfirm')">
          <el-radio-group v-model="formMessages.isLeaveMsg">
            <el-radio label="1">{{$t('public.yes')}}</el-radio>
            <el-radio label="0">{{$t('public.no')}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="$t('configLazyLoad.webimClient.defaultTips18')" v-show="formMessages.isLeaveMsg==='1'">
          <el-input type="textarea" v-model="formMessages.inviteLeavemsgTip" :placeholder="$t('configLazyLoad.webimClient.defaultTips1')"></el-input>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips2')}}</p>
        </el-form-item>
        <el-form-item :label="$t('configLazyLoad.webimClient.defaultTips19')" v-show="formMessages.isLeaveMsg==='1'">
          <el-input type="textarea" v-model="formMessages.leavemsgTip" :placeholder="$t('configLazyLoad.webimClient.defaultTips3')"></el-input>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips7')}}</p>
        </el-form-item>
        <el-form-item :label="$t('configLazyLoad.webimClient.defaultTips20')" v-show="formMessages.isLeaveMsg==='0'">
          <el-input v-model="formMessages.msg" type="textarea" :placeholder="$t('configLazyLoad.webimClient.defaultTips4')"></el-input>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips5')}}</p>
        </el-form-item>
        <div class="title" v-show="formMessages.isLeaveMsg==='1'">{{$t('configLazyLoad.webimClient.defaultTips6')}}</div>
        <el-form-item class="field_item" v-show="formMessages.isLeaveMsg==='1'" v-for="(item, index) in formMessages.leavemsgFields" :key="index" :prop="'leavemsgFields.' + index + '.name'" :rules="{required: true, message: $t('configLazyLoad.webimClient.leaveMessage9'), trigger: 'blur'}">
          <el-row>
            <el-col :span="16">
              <el-input type="text" v-model.trim="item.name" :placeholder="$t('configLazyLoad.webimClient.defaultTips8')" :maxlength="10"></el-input>
            </el-col>
            <el-col :span="3" style="text-align: center">
              <el-checkbox v-model="item.enable">{{$t('configLazyLoad.public.reuse')}}</el-checkbox>
            </el-col>
            <el-col :span="3" style="text-align: center">
              <el-checkbox v-model="item.required">{{$t('validate.required')}}</el-checkbox>
            </el-col>
            <el-col :span="2" style="text-align: center">
              <el-button class="edit_del el-icon-minus color" type="text" size="mini" @click.prevent="removeFieldItem(index)"></el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item v-show="formMessages.isLeaveMsg==='1'">
          <el-button type="text" @click.stop="addFildsItem" size="small" class="color el-icon-plus"> {{$t('configLazyLoad.webimClient.addFields')}}</el-button>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips9')}}</p>
        </el-form-item>
        <el-form-item>
          <div class="title">{{$t('configLazyLoad.webimClient.defaultTips10')}}</div>
          <el-radio-group v-model="formMessages.queueNumSwitch">
            <el-radio :label="true">{{$t('public.yes')}}</el-radio>
            <el-radio :label="false">{{$t('public.no')}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-show="formMessages.queueNumSwitch" :label="$t('configLazyLoad.webimClient.defaultTips11')">
          <el-input type="textarea" v-model="formMessages.queueNumText" :placeholder="$t('configLazyLoad.webimClient.defaultTips12')"></el-input>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips13')}}</p>
        </el-form-item>
        <el-form-item>
          <div class="title">{{$t('configLazyLoad.webimClient.defaultTips14')}}</div>
          <el-radio-group v-model="formMessages.replaceCustSwitch">
            <el-radio label="1">{{$t('public.yes')}}</el-radio>
            <el-radio label="0">{{$t('public.no')}}</el-radio>
          </el-radio-group>
          <div v-show="formMessages.replaceCustSwitch==='1'">
            <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips15')}}</p>
            <el-radio-group v-model="formMessages.replaceCustomer">
              <el-radio label="random">{{$t('configLazyLoad.webimClient.randomReplace')}}</el-radio>
              <el-radio label="list">{{$t('configLazyLoad.webimClient.chooseAgent')}}</el-radio>
            </el-radio-group>
            <p class="tip_item">{{$t('configLazyLoad.webimClient.chooseAgentType')}}</p>
          </div>
          <div class="title">{{$t('configLazyLoad.webimClient.sessionType1')}}</div>
          <el-radio-group v-model="formMessages.accessAfterMessage">
            <el-radio label="1">{{$t('configLazyLoad.public.reuse')}}</el-radio>
            <el-radio label="0">{{$t('configLazyLoad.public.noReuse')}}</el-radio>
          </el-radio-group>
          <div class="title">
            {{$t('configLazyLoad.webimClient.sessionType2')}}
            <el-tooltip content="温馨提示：在设置会话断开时，断开前提醒时间点的数值需小于访客无响应断开对话时长的数值"
                placement="right" effect="dark">
              <span class="tooltip"><i class="iconfont icon-tixingweizhi"></i></span>
            </el-tooltip>
          </div>
          <el-form-item :label="$t('configLazyLoad.webimClient.sessionType3')" prop="break_len" :rules="{ required: true, message: this.$t('validate.required'), trigger: 'blur'}">
            <el-input  type="age" v-model.trim="formMessages.break_len">
              <template slot="append">{{$t('public.minutes2')}}</template>
            </el-input>
            <p class="tip_item">{{$t('configLazyLoad.webimClient.sessionType7')}}</p>
          </el-form-item>
          <el-form-item :label="$t('configLazyLoad.webimClient.sessionType4')" prop="break_tips_len" :rules="{required: true, message: this.$t('validate.required'), trigger: 'blur'}">
            <el-input type="age" v-model.trim="formMessages.break_tips_len" >
              <template slot="append">{{$t('public.minutes2')}}</template>
            </el-input>
            <p class="tip_item">{{$t('configLazyLoad.webimClient.sessionType5')}}</p>
          </el-form-item>
          <el-form-item :label="$t('configLazyLoad.webimClient.sessionType6')">
            <el-input v-model="formMessages.break_tips" type="textarea"></el-input>
            <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips16')}}</p>
          </el-form-item>
          <el-form-item :label="$t('configLazyLoad.webimClient.defaultTips21')">
            <el-input v-model="formMessages.finishText" type="textarea"></el-input>
            <p class="tip_item">{{$t('configLazyLoad.webimClient.defaultTips17')}}</p>
          </el-form-item>
        </el-form-item>
        <el-form-item>
          <span class="title" style="margin-right: 30px">{{$t('configLazyLoad.webimClient.agentReadeMessageState')}}</span>
          <el-switch
            v-model="formMessages.isCustomerRead"
            :active-text="$t('configLazyLoad.public.open')"
            :inactive-text="$t('configLazyLoad.public.close')">
          </el-switch>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.agentReadeMessageTip')}}</p>
        </el-form-item>
        <el-form-item>
          <span class="title" style="margin-right: 30px">{{$t('configLazyLoad.webimClient.agentStatusLabel')}}</span>
          <el-switch
            v-model="formMessages.isAgentStatus"
            :active-text="$t('configLazyLoad.public.open')"
            :inactive-text="$t('configLazyLoad.public.close')">
          </el-switch>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.agentStatusTip')}}</p>
          <p v-if="formMessages.isAgentStatus" class="tip_item">{{$t('configLazyLoad.webimClient.agentStatusTip1')}}</p>
          <el-input v-if="formMessages.isAgentStatus" v-model="formMessages.agentStatusMessage" type="textarea"></el-input>
          <p class="tip_item" v-if="formMessages.isAgentStatus">{{$t('configLazyLoad.webimClient.agentStatusTip2')}}</p>
        </el-form-item>
        <div class="title">{{$t('configLazyLoad.webimClient.QueueAbandonSettings')}}</div>
        <el-form-item class="vip_access section-top">
          <div class="label_box">{{$t('configLazyLoad.webimClient.QueueAbandonSettingsOpenTip')}}:</div>
          <el-switch v-model="formMessages.isGiveUpConfig"></el-switch>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.QueueAbandonSettingsTip')}}</p>
        </el-form-item>
        <el-form-item class="priority_box" v-show="formMessages.isGiveUpConfig">
          <p class="queue-time-box label_box">
            <span>{{$t('configLazyLoad.webimClient.QueueAbandonSettingsTimeTitle')}}</span>
            <el-input-number @change="onChange" :controls="false" v-model="formMessages.giveUpTime" :min="1" :max="20"/>
            <span>{{$t('configLazyLoad.webimClient.QueueAbandonSettingsTimeTime')}}</span>
          </p>
          <p class="tip_item">{{$t('configLazyLoad.webimClient.QueueAbandonSettingsTimeTip')}}</p>
        </el-form-item>
        <el-form-item class="padding-top">
          <el-button type="primary" @click="submitFormSensitive" class="fr primary_btn">{{$t('public.save')}}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips2')}}</div>
      <visitorWaitConfig></visitorWaitConfig>
    </div>
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips3')}}</div>
      <weChatClient></weChatClient>
    </div>
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips4')}}</div>
      <enterpriseWebimSet></enterpriseWebimSet>
    </div>
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips5')}}</div>
      <TikTokWebimSet></TikTokWebimSet>
    </div>
    <!-- 移动APP客服访客输入状态提示 -->
    <div class="contant">
      <div class="tip">{{$t('configLazyLoad.webimClient.titleTips6')}}</div>
      <AppTypeNotice></AppTypeNotice>
    </div>
  </div>
</template>
<script>
  import weChatClient from '../weixin/weChatClient.vue'
  import enterpriseWebimSet from '../enterprise/enterpriseWebimSet.vue'
  import TikTokWebimSet from '../tikTok/TikTokWebimSet.vue'
  import visitorWaitConfig from './visitorWaitConfig'
  import AppTypeNotice from './appTypeNotice.vue'
  import { deepClone, isHasMenu } from '@/utils/m7Utils.js'
  export default {
    name: 'webimClient',
    data () {
      return {
        formMessages: {
          _id: '',
          filterSensitiveWords: true, // 敏感词屏蔽开关
          sensitiveWords: '', // 敏感词提示
          focusWords: '',
          focusSensitiveWords: '1', // 是否开启敏感词提示开关
          isLeaveMsg: '1',           // 是否启用留言
          leavemsgTip: this.$t('configLazyLoad.webimClient.leaveMessage1'),      // 留言框填写内容
          inviteLeavemsgTip: this.$t('configLazyLoad.webimClient.leaveMessage2'),      // 留言框标题填写内容
          replaceCustomer: 'list',   // 设定更换客服的方式
          replaceCustSwitch: '1',    // 更换客服方式
          accessAfterMessage: '1',
          queueNumSwitch: false,     // 启用排队人数提示
          queueNumText: '',     // 排队提示文案
          msg: '',                   // 推送内容
          leavemsgFields: [],         // 自定义留言字段
          backgroundColor: '#FF0000', // 自定义敏感词底色
          filterSensitiveMessage: '0', // 是否短信通知
          filterSensitiveTel: '', // 短信通知手机号，逗号分隔
          filterMessageTemp: '0', // 短信模板id
          filterMessageStartDate: '*', // 短信通知开始日期
          filterMessageEndDate: '*', // 短信通知结束日期
          filterMessageStartTime: '*', // 短信通知开始时间
          filterMessageEndTime: '*', // 短信通知结束时间
          weekMon: true, // 短信通知周一
          weekTue: true, // 短信通知周二
          weekWed: true, // 短信通知周三
          weekThu: true, // 短信通知周四
          weekFri: true, // 短信通知周五
          weekSat: true, // 短信通知周六
          weekSun: true,  // 短信通知周日
          openPriority: false,  // 是否开启优先进线功能
          isCustomerRead: false,  // 访客端消息已读未读状态设置
          priorityList: [],
          break_len: '10',  // 访客无响应断开对话时长
          break_tips_len: '3',  // 断开前提示时间点
          break_tips: '', // 断开前提示内容
          finishText: '',  // 结束会话后访客端提示语
          customFieldPriority: '',
          customFieldPriorityWords: '',
          isAgentStatus: false,
          agentStatusMessage: ''
        },
        custArray: [],  //  客户状态数组
        smsTemplates: []
      }
    },
    components: {
      weChatClient,
      enterpriseWebimSet,
      TikTokWebimSet,
      visitorWaitConfig,
      AppTypeNotice
    },
    computed: {
      filterSensitiveTelLength () {
        let length = 0
        if (this.formMessages.filterSensitiveTel !== '') {
          let arr = this.formMessages.filterSensitiveTel.split(',')
          length = arr.length
          if (arr[length - 1] === '') {
            length = length - 1
          }
        }
        return length
      }
    },
    methods: {
      onChange (val) {
        this.formMessages.giveUpTime = Number.parseInt(val)
      },
      isHasMenuShow (key) {
        return isHasMenu(key, this.$store.state.session.user)
      },
      changeColor (color) {
        if (!color) {
          this.formMessages.backgroundColor = '' // 自定义敏感词底色
        }
      },
      init (obj) {
        for (var item in this.formMessages) {
          if (obj.filterSensitiveWords === '1') { // 屏蔽敏感词开关
            this.formMessages.filterSensitiveWords = true
          } else {
            this.formMessages.filterSensitiveWords = false
          }
          if (obj.focusSensitiveWords === '1') { // 敏感词提示开关
            this.formMessages.focusSensitiveWords = '1'
          } else {
            this.formMessages.focusSensitiveWords = '0'
          }
          if (item === 'backgroundColor') {
            if (obj[item]) {
              obj[item] = obj[item].replace(/#/g, '')
              this.formMessages.backgroundColor = '#' + obj[item]
            } else {
              this.formMessages.backgroundColor = '#FF0000'
            }
          } else {
            this.formMessages[item] = obj[item] === undefined ? this.formMessages[item] : obj[item]
          }
        }
        if (!this.formMessages.openPriority) {
          this.$set(this.formMessages, 'openPriority', false)
        }
        if (!this.formMessages.isCustomerRead) {
          this.$set(this.formMessages, 'isCustomerRead', false)
        }
        if (!this.formMessages.isAgentStatus) {
          this.$set(this.formMessages, 'isAgentStatus', false)
        }
        if (!this.formMessages.priorityList) {
          this.$set(this.formMessages, 'priorityList', [])
        }
        this.$set(this.formMessages, 'isGiveUpConfig', obj.isGiveUpConfig)
        this.$set(this.formMessages, 'giveUpTime', obj.giveUpTime || 1)
        if (this.formMessages.priorityList && this.formMessages.priorityList.length && this.custArray.length) {
          let priorityList = deepClone(this.formMessages.priorityList)
          priorityList.forEach((list) => {
            this.custArray.forEach((item) => {
              if (item.status === list) {
                this.$set(item, 'checked', true)
              }
            })
          })
        }
      },
      saveFilterWords () { // 保存敏感词过滤
        let backgroundColor = deepClone(this.formMessages.backgroundColor)
        if (backgroundColor.indexOf('undefined') > -1) {
          backgroundColor = '#FF0000'
        }
        let newColor = backgroundColor.replace(/#/g, '')
        if (!newColor) {
          this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage3'))
          return
        }
        if (this.formMessages.filterSensitiveMessage === '1') {
          if (this.formMessages.filterMessageTemp === '0') {
            this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage4'))
            return
          }
          let telArr = this.formMessages.filterSensitiveTel.split(',')
          let newArr = telArr.filter((item, index, array) => {
            return array.indexOf(item) === index
          })
          this.formMessages.filterSensitiveTel = newArr.join(',')
          if (newArr.length > 20) {
            this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage5'))
            return
          }
        }
        let priorityArr = []
        this.custArray.forEach((item) => {
          if (item.checked) {
            priorityArr.push(item.status)
          }
        })
        let data = {
          ...this.formMessages,
          _id: this.formMessages._id,
          filterSensitiveWords: this.formMessages.filterSensitiveWords ? '1' : '0',
          focusSensitiveWords: this.formMessages.focusSensitiveWords == '1' ? '1' : '0',
          focusWords: this.formMessages.focusWords,
          sensitiveWords: this.formMessages.sensitiveWords,
          backgroundColor: newColor,
          filterSensitiveMessage: this.formMessages.filterSensitiveMessage, // 是否短信通知
          filterSensitiveTel: this.formMessages.filterSensitiveTel, // 短信通知手机号，逗号分隔
          filterMessageTemp: this.formMessages.filterMessageTemp, // 短信模板id
          filterMessageStartDate: this.formMessages.filterMessageStartDate, // 短信通知开始日期
          filterMessageEndDate: this.formMessages.filterMessageEndDate, // 短信通知结束日期
          filterMessageStartTime: this.formMessages.filterMessageStartTime, // 短信通知开始时间
          filterMessageEndTime: this.formMessages.filterMessageEndTime, // 短信通知结束时间
          weekMon: this.formMessages.weekMon, // 短信通知周一
          weekTue: this.formMessages.weekTue, // 短信通知周二
          weekWed: this.formMessages.weekWed, // 短信通知周三
          weekThu: this.formMessages.weekThu, // 短信通知周四
          weekFri: this.formMessages.weekFri, // 短信通知周五
          weekSat: this.formMessages.weekSat, // 短信通知周六
          weekSun: this.formMessages.weekSun,  // 短信通知周日
          openPriority: this.formMessages.openPriority,  // 是否开启优先进线功能
          isCustomerRead: this.formMessages.isCustomerRead,  // 是否访客端消息已读未读
          isAgentStatus: this.formMessages.isAgentStatus,
          agentStatusMessage: this.formMessages.agentStatusMessage,
          customFieldPriority: this.formMessages.customFieldPriority,
          customFieldPriorityWords: this.formMessages.customFieldPriorityWords,
          priorityList: priorityArr   // 优先进线客户数组
        }
        this.$store.dispatch('saveGlobalSet', data).then(res => {
          if (res && res.success) {
            this.$message.success(this.$t('configLazyLoad.webimClient.setingSuccess'))
          }
        })
      },
      removeFieldItem (index) {
        if (this.formMessages.leavemsgFields) {
          this.formMessages.leavemsgFields.splice(index, 1)
        }
      },
      addFildsItem () {
        if (this.formMessages.leavemsgFields && this.formMessages.leavemsgFields.length < 10) {
          this.formMessages.leavemsgFields.push({name: '', enable: false, required: false})
        } else {
          this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage6'))
        }
      },
      submitFormSensitive () { // 保存自定义留言设置
        let formData = deepClone(this.formMessages)
        delete formData.filterSensitiveWords
        let breakLen = parseFloat(formData.break_len)
        if (typeof breakLen !== 'number' || breakLen < 1 || Math.floor(breakLen) !== breakLen) {
          this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage7'))
          return
        }
        let breakTips = parseFloat(formData.break_tips_len)
        if (typeof breakTips !== 'number' || breakTips < 1 || Math.floor(breakTips) !== breakTips) {
          this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage8'))
          return
        }
        this.$refs.formMessages.validate((valid) => {
          if (valid) {
            this.$store.dispatch('saveGlobalSet', formData).then((rep) => {
              if (rep.success) {
                this.$message.success(this.$t('config.channel.configSuccess'))
              } else {
                this.$message.error(this.$t('qualityCheck.saveFali'))
              }
            })
          } else {
            this.$message.error(this.$t('configLazyLoad.webimClient.leaveMessage9'))
            return false
          }
        })
      },
      getSmsTemplate () {
        // 获取短信模板
        this.$store.dispatch('getSelectSms').then((SelectSms) => {
          if (SelectSms) {
            this.smsTemplates = SelectSms
            console.log(this.smsTemplates)
          }
        })
      }
    },
    beforeMount () {
      this.getSmsTemplate()
      let p1 = this.$store.dispatch('getGlobalSetById', {})
      let p2 = this.$store.dispatch('getCustomerTemplate', {account: this.$store.state.session.user.account})
      Promise.all([p1, p2]).then(([res1, res2]) => {
        if (res2 && res2.data && res2.data.length) {
          let row = res2.data[0].status
          if (row) {
            this.custArray = []
            for (let m in row) {
              let obj = {
                status: m,
                name: row[m],
                checked: false
              }
              this.custArray.push(obj)
            }
          }
        }
        if (res1 && res1.row) {
          this.init(res1.row)
        }
      })
    }
  }
</script>
<style>
  .smsCheckLabel .el-checkbox__label {
    font-size: 14px;
  }
</style>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
  .wrap
    padding 0px 16px
  .title
    font-weight: 900
    font-size: 14px
    margin-bottom: 5px
  
  .section-top
    margin-top 18px

  .queue-time-box
    >>> .el-input-number
        width 40px
        margin 0 5px
    >>>.el-input__inner
        padding-left 5px
        padding-right 5px
  .tip
    padding-bottom 15px
    color $c-prompt
  .padding-top
    padding-top 15px
  .contant
    padding 20px 0
    border-bottom 1px solid $c-border2
  .form
    width 500px
    .tip_item
      color $cf-gray4
      font-size 12px
      padding 5px 0
  .color-demo
    display inline-block
    height 30px
    margin-right 20px
    width 70px
    vertical-align bottom
    border-radius 2px
    border 1px solid #bfcbd9
    box-sizing border-box
  .color-picker
    height 30px
    padding-bottom 5px
    vertical-align bottom
  .sms-select-option
    max-width 500px
    height auto
    word-wrap break-word
    white-space normal
    line-height 20px
    padding 10px 20px
  .smsNotify
    padding: 10px 0 16px;
    .smsCheck
      span
        font-size 14px
    .timeTitle
      margin: 10px 0;
      padding-left: 20px;
    .timeZone
      padding-left 40px
      .notifyDate
        .el-input
          width: 45%;
          margin-right: 5%;
      .week
        margin-bottom: 5px
      .prompit
        color $c-prompt
        line-height: 16px;
        padding: 6px 0 12px;
        font-size: 12px;
    .notifySmsTemp
      padding-left:20px
      .red
        display: inline-block;
        color: red;
        margin-right: 4px;
        font-weight: 700;
      .el-select
        width: 80%;
        display: inline-block;
    .notifyTitle
      width: 90px;
      display: inline-block;
    .notifyDesc
      color: #3b5998;
    .notifySmsNumber
      padding-left 20px
      .el-textarea
        width: 80%;
        display: inline-block;
        vertical-align: text-top;
      .red
        color: red
        font-weight 700
  .sms-select-option.selected
    .sms-title-b
      color $cf-color1
  .sms-title-b
     color $cf-gray0
  .vip_access
    line-height 30px
  .label_box
    font-size 12px
    display inline-block
    margin-right 20px
  .priority_box
    .priority_item
      height 40px
      .el-checkbox
        vertical-align top
    div,.priority_item_name
      font-size 12px
  .priority_item_name
    margin-right: 10px
    display: inline-block
    overflow: hidden
    text-overflow: ellipsis
    white-space: nowrap
    width: 140px
  .tooltip
    color #3a87ad
    display inline-block
    height 16px
    width 16px
    text-align center
    line-height 16px
    margin 0 12px
    position relative
    font-size 10px
    .iconfont
      font-size 10px
      color $c-main
    .icon-tixingweizhi
      border 1px solid $c-main
      border-radius 50%
      display inline-block
      height 16px
      width 16px
      text-align center
      line-height 16px
      position relative
      top -1px
      font-size 10px
  .customFieldPriority
    width 40%
    margin 0px 10px   
</style>
